<template>
  <section>
    <el-form label-width="80px" size="mini">
      <el-form-item label="sn">
        <el-input style="width: 200px" v-model="courseDefine.sn" placeholder="请匹配产品sn" />
      </el-form-item>
      <el-form-item label="标题">
        <el-input style="width: 200px" v-model="courseDefine.title" placeholder="请输入课程名" />
      </el-form-item>
      <el-form-item label="学员">
        <el-switch v-model="courseDefine.userType" active-color="#409EFF" inactive-color="#13ce66"
                   active-text="账户" inactive-text="用户"
                   active-value="1" inactive-value="2" />
      </el-form-item>
      <el-form-item label="描述">
        <el-input style="width: 400px" type="textarea" v-model="courseDefine.description" placeholder="请输入课程详情描述" />
      </el-form-item>
      <el-form-item label="">
        <el-button size="mini" type="success" @click="confirmBtn(courseDefine)">{{courseDefine.id?'保存':'新建'}}</el-button>
      </el-form-item>
    </el-form>
  </section>
</template>

<script>
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  import Vue from 'vue'//后续添加属性，需要vue联动
  import errHandler from '@/assets/errHandler'
  import dateFormater from '@/common/date-formater'
  export default {
    name: "editDefine",
    props:['courseDefine'],
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      confirmBtn(define){
        console.log('看下提交了个啥？？？',define)
        // return
        if(define.id) this.updateCourseDefine(define)
        else this.createCourseDefine(define)
      },
      updateCourseDefine(data){
        this.fetch({name:"updateCourseDefine",data})
          .then(res=>{
            this.$message({type:'success',message:'更新成功！'})
            this.$emit('cancel')
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      createCourseDefine(data){
        this.fetch({name:"createCourseDefine",data})
          .then(res=>{
            this.$message({type:'success',message:'新建成功！'})
            this.$emit('cancel')
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      }
    }
  }
</script>

<style scoped>

</style>
